package com.tycmc.signelectroniccontracts.act.renzheng.qiye;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.tycmc.signelectroniccontracts.R;
import com.tycmc.signelectroniccontracts.logic.renzheng.qiye.PreDuiGongDaKuan;
import com.tycmc.signelectroniccontracts.tools.base.FraBase;
import com.tycmc.signelectroniccontracts.tools.other.TextShow;
import com.tycmc.signelectroniccontracts.tools.show.ToastShow;
import com.tycmc.signelectroniccontracts.tools.store.SharePre;
import com.tycmc.signelectroniccontracts.tools.store.SharePreName;

import java.util.HashMap;
import java.util.Map;

public class FraDuiGongDakuan extends FraBase implements PreDuiGongDaKuan.DuiGongDaKuanInterface {

    private PreDuiGongDaKuan pre;
    private Map upMap;

    public FraDuiGongDakuan(Map upMap) {
        pre = new PreDuiGongDaKuan(this);
        this.upMap = upMap;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fra_duigongdakuan, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        pre.initData(upMap);
    }

    private void initView() {
        TextShow.setTextNeed((TextView) getView().findViewById(R.id.tv_jiaoyijine_state));
        TextShow.setTextNeed((TextView) getView().findViewById(R.id.tv_yanzhengma_state));
        getView().findViewById(R.id.tv_next).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Map upMap = getUpMap();
                if (upMap !=null) {
                    pre.upData(upMap);
                }
            }
        });
    }

    public Map getUpMap() {
        Map map = new HashMap();
        String jiaoyijine = ((TextView) getView().findViewById(R.id.et_jiaoyijine)).getText().toString().trim();
        String yanzhengma = ((TextView) getView().findViewById(R.id.et_yanzhengma)).getText().toString().trim();
        if (TextShow.isEmpty(jiaoyijine)) {
            ToastShow.popupToast("请输入交易金额");
            return null;
        }
        if (TextShow.isEmpty(yanzhengma)) {
            ToastShow.popupToast("请输入验证码");
            return null;
        }
        map.put("amount",jiaoyijine);
        map.put("verificationCode",yanzhengma);
        map.put("clientArchiveNo", SharePre.getString(SharePreName.clientArchiveNo,""));
        return map;
    }

    @Override
    public void initData(String yinghangmingcheng, String yinghangdizhi, String yinghangzhanghao) {
        ((TextView) getView().findViewById(R.id.tv_yinhangmingcheng)).setText(yinghangmingcheng);
        ((TextView) getView().findViewById(R.id.tv_yinhangdizhi)).setText(yinghangdizhi);
        ((TextView) getView().findViewById(R.id.tv_yinhangzhanghao)).setText(yinghangzhanghao);
    }
}
